﻿<?php
    include_once "vendor/autoload.php";
    include_once "SimpleDBApi_MS_PDO.php";
    
    use Monolog\Logger;
    use Monolog\Handler\StreamHandler;
    use Monolog\Handler\ErrorLogHandler;
    $logger = new Logger('xlib_php');
    $logger->pushHandler(new StreamHandler(__DIR__ . '/run_dir/log/xlib_php.log', Logger::INFO));
    $logger->info("测试monolog日志输出");
     
    header("Content-Type: text/html; charset=utf-8");
 
    echo "__FILE__" . __DIR__;
    echo "</br>";
    echo "__FILE__" . __FILE__;
    echo "</br>";
    echo "安装路径：" . dirname(__FILE__);
    echo "</br>";
    
    $bRet = false;

    // 创建数据库对象
    $dbApi = new SimpleDBApi_MS_PDO();
    // 连接数据库
    $bRet = $dbApi->Connect("127.0.0.1", 1433, "QPAccountsDB", "enic", "cl_gamer123");
    if(true != $bRet)
    {
        echo "数据库连接失败！";
    }

    // 生成预处理
    $dbApi->Prepare("select * from AccountsInfo");
    // 参数绑定
    //$dbApi->BindParam(":Accounts", "%enic%");
    // 执行
    if(true != $dbApi->Execute())
    {
        echo "执行失败";
        return ;
    }
    
    echo "<table border=\"1\">";
    echo "<tr> <td>KindId</td> <td>PrivateTableId</td> </tr>";
    while($row = $dbApi->Fetch()) 
    {
        echo "<tr>";
        echo "<td>" . $row['UserID'] . "</td>";
        echo "<td>" . $row['Accounts'] . "</td>";
        echo "</tr>";
    }
    echo "</table>";
    
    /*
    echo "<br/>";
    error_log("---");
    $dbHostName = "192.168.16.23";
    $dbPort     = 1433;
    $dbName     = "QPAccountsDB";
    $dbUserName = "sa";
    $dbPassword = "sa";
    $dbConnString = "sqlsrv:Server=" . $dbHostName . "," . $dbPort . ";Database=" . $dbName;
    echo "连接字符串：" . $dbConnString;
    echo "<br/>";
    $dbConnInfo = array("UID"=>$dbUserName, "PWD"=>$dbPassword, "Database"=>"QPAccountsDB");
  */  
    //$dbConn = sqlsrv_connect($dbHostName, $dbConnInfo);
    //echo var_dump($dbConn);
 
 /*   测试mssql 
    try {
        // 用持久链接打开数据库 array(PDO::ATTR_PERSISTENT => true)
        $pdo_obj = new PDO($dbConnString, $dbUserName, $dbPassword);
        // 防止注入
        $pdo_obj->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
        
        $prepare = $pdo_obj->prepare('SELECT * FROM AccountsInfo WHERE Accounts LIKE(?)');
        $strAcc = "%enic%";
        $prepare->bindParam(1, $strAcc);
        $prepare->execute();
        
        echo "<table border=\"1\">";
        echo "<tr> <td>UserID</td> <td>NickName</td> </tr>";
        
        while($row = $prepare->fetch()) {
            echo "<tr>";
            echo "<td>" . $row['UserID'] . "</td>";
            echo "<td>" . $row['NickName'] . "</td>";
            echo "</tr>";
        }
        
        echo "</table>";
    } catch(PDOException $e) {
        echo "数据库访问异常：" . $e->getMessage();
    }
 */
 
 /*   测试mysql
    try {
        // 连接数据库
        $pdo_obj = new PDO('mysql:host=127.0.0.1;dbname=db_all_in_one', 'enic', 'cl_gamer123');
        // 防止注入
        $pdo_obj->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
        // 设置文字编码集
        $pdo_obj->query('SET NAMES utf8');
        // 设置严格语法模式
        $pdo_obj->query('set session sql_mode=\'STRICT_TRANS_TABLES,ONLY_FULL_GROUP_BY,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION\'');
    } catch(PDOException $e) {
        echo "数据库访问异常：" . $e->getMessage();
    }
    
    
    $select_result = $pdo_obj->query('select msg, datetime from tb_test_partition');
    
    // 输出表
    echo "<table>";
    echo "<tr> <td>msg</td> <td>datatime</td> </tr>";
    while($row = $select_result->fetch()) {
        echo "<tr>";
        echo "<td>" . $row['msg'] . "</td>";
        echo "<td>" . $row['datetime'] . "</td>";
        echo "</tr>";
    }
    echo "</table>"
*/
?>
